/*++

Copyright (c) 2007  Microsoft Corporation 

Filename: 

    ExceptionForm.cs

Abstract: 

    Form to handle Exceptions
     
--*/
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace NRTMAddIn
{
	/// <summary>
	/// Summary description for ExceptionForm.
	/// </summary>
	[System.Runtime.InteropServices.ComVisible(false)]
	public class ExceptionForm : System.Windows.Forms.Form
	{
		#region fields

		//Show Details Toggle Flag
		private bool m_showingDetails = true;

		#endregion

		#region controls

        //Form components variable
		private System.Windows.Forms.Button buttonShowHideDetails;
		private System.Windows.Forms.TextBox textBoxDetails;
		private System.Windows.Forms.Label labelMessage;
		private System.Windows.Forms.Label labelShowDetails;
		private System.Windows.Forms.Label labelHideDetails;
		private System.Windows.Forms.Button buttonOK;

		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		#endregion

		#region construction / destruction

		/// <summary>
		/// Constructor
		/// </summary>
		public ExceptionForm(
			bool showDetailsOnDisplay,
			string caption,
			string userMessage,
			string exceptionDetails)
		{
			InitializeComponent();
            this.labelMessage.Text = Global.GetResourceString("Exception_UsrMsg")
                + Global.GetResourceString("Dot");
            this.buttonShowHideDetails.Text = Global.GetResourceString("Exception_Show");
            this.buttonOK.Text = Global.GetResourceString("OKButton_Text");
            this.textBoxDetails.Text = Global.GetResourceString("Exception_Details");
            this.labelShowDetails.Text = Global.GetResourceString("Exception_Show");
            this.labelHideDetails.Text = Global.GetResourceString("Exception_Hide");
            this.Text = Global.GetResourceString("ExceptionForm_Text");
            

			// set the caption
			this.Text = caption;

			// set the messages and details
			this.labelMessage.Text = userMessage;
			this.textBoxDetails.Text = exceptionDetails;

			// format the form to hide of show details
			ToggleDetails(showDetailsOnDisplay);
            
		}


		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            this.labelMessage = new System.Windows.Forms.Label();
            this.buttonShowHideDetails = new System.Windows.Forms.Button();
            this.buttonOK = new System.Windows.Forms.Button();
            this.textBoxDetails = new System.Windows.Forms.TextBox();
            this.labelShowDetails = new System.Windows.Forms.Label();
            this.labelHideDetails = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // labelMessage
            // 
            this.labelMessage.Location = new System.Drawing.Point(8, 16);
            this.labelMessage.Name = "labelMessage";
            this.labelMessage.Size = new System.Drawing.Size(416, 66);
            this.labelMessage.TabIndex = 0;            
            // 
            // buttonShowHideDetails
            // 
            this.buttonShowHideDetails.Location = new System.Drawing.Point(248, 90);
            this.buttonShowHideDetails.Name = "buttonShowHideDetails";
            this.buttonShowHideDetails.Size = new System.Drawing.Size(88, 23);
            this.buttonShowHideDetails.TabIndex = 1;            
            this.buttonShowHideDetails.Click += new System.EventHandler(this.buttonShowHideDetails_Click);
            // 
            // buttonOK
            // 
            this.buttonOK.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.buttonOK.Location = new System.Drawing.Point(344, 90);
            this.buttonOK.Name = "buttonOK";
            this.buttonOK.Size = new System.Drawing.Size(75, 23);
            this.buttonOK.TabIndex = 2;            
            // 
            // textBoxDetails
            // 
            this.textBoxDetails.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                        | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.textBoxDetails.Location = new System.Drawing.Point(8, 120);
            this.textBoxDetails.Multiline = true;
            this.textBoxDetails.Name = "textBoxDetails";
            this.textBoxDetails.ReadOnly = true;
            this.textBoxDetails.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
            this.textBoxDetails.Size = new System.Drawing.Size(416, 158);
            this.textBoxDetails.TabIndex = 3;            
            // 
            // labelShowDetails
            // 
            this.labelShowDetails.Location = new System.Drawing.Point(8, 96);
            this.labelShowDetails.Name = "labelShowDetails";
            this.labelShowDetails.Size = new System.Drawing.Size(100, 16);
            this.labelShowDetails.TabIndex = 4;            
            this.labelShowDetails.Visible = false;
            // 
            // labelHideDetails
            // 
            this.labelHideDetails.Location = new System.Drawing.Point(104, 96);
            this.labelHideDetails.Name = "labelHideDetails";
            this.labelHideDetails.Size = new System.Drawing.Size(100, 16);
            this.labelHideDetails.TabIndex = 5;            
            this.labelHideDetails.Visible = false;
            // 
            // ExceptionForm
            // 
            this.AcceptButton = this.buttonOK;
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.CancelButton = this.buttonOK;
            this.ClientSize = new System.Drawing.Size(432, 288);
            this.ControlBox = false;
            this.Controls.Add(this.labelHideDetails);
            this.Controls.Add(this.labelShowDetails);
            this.Controls.Add(this.textBoxDetails);
            this.Controls.Add(this.buttonOK);
            this.Controls.Add(this.buttonShowHideDetails);
            this.Controls.Add(this.labelMessage);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "ExceptionForm";
            this.ShowInTaskbar = false;
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;            
            this.ResumeLayout(false);
            this.PerformLayout();

		}

		#endregion

		#endregion

		#region methods

		/// <summary>
		/// Turn the details view on or off.
		/// </summary>
		/// <param name="showDetails">
		/// True - shows details
		/// False - hides details
		/// </param>
		private void ToggleDetails(
			bool showDetails)
		{
			// toggle the local flag
			m_showingDetails = showDetails;

			// size the dialog appropriately
			if (m_showingDetails)
			{
				this.Height = textBoxDetails.Top + 200;
				buttonShowHideDetails.Text = labelHideDetails.Text;
			}
			else
			{
				this.Height = buttonOK.Top + 60;
				buttonShowHideDetails.Text = labelShowDetails.Text;
			}

			// default return
			return;
		}

		#endregion

		#region control events

		/// <summary>
		/// Show or hide the details of the exception.
		/// </summary>
		/// <param name="sender">
		/// </param>
		/// <param name="e">
		/// </param>
		private void buttonShowHideDetails_Click(
			object sender,
			System.EventArgs e)
		{
			// toggle the detail visibility state
			ToggleDetails(!m_showingDetails);

			// default return
			return;
		}

		#endregion     
    }
}
